package org.test.client.ui.skinui.checkbox;

import java.awt.Component;
import java.awt.Graphics;
import java.io.Serializable;

import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.plaf.UIResource;

/**
 * RadioButton��ͼ��ʵ����.
 */
public class RadioButtonIcon implements Icon, UIResource, Serializable {

	public void paintIcon(Component c, Graphics g, int x, int y) {
		AbstractButton b = (AbstractButton) c;
		ButtonModel model = b.getModel();

		// ѡ��ʱ
		if (model.isSelected()) {
			// ���ڽ���״̬
			if (!model.isEnabled())
				g.drawImage(PicFactory.getRadioIcon(PicFactory.RB_DISABLE), x, y, null);
			else {
				// ���ڱ���ס״̬
				if (model.isPressed())
					g.drawImage(PicFactory.getRadioIcon(PicFactory.RB_PRESSED), x, y, null);
				else
					g.drawImage(PicFactory.getRadioIcon(PicFactory.RB_NORMAL), x, y, null);
			}
		}
		// δѡ��ʱ
		else {
			// ���ڽ���״̬
			if (!model.isEnabled())
				g.drawImage(PicFactory.getRadioIcon(PicFactory.RB_UN_DISABLE), x,y, null);
			else {
				// ���ڱ���ס״̬
				if (model.isPressed())
					g.drawImage(PicFactory.getRadioIcon(PicFactory.RB_UN_PRESSED), x, y, null);
				else
					g.drawImage(PicFactory.getRadioIcon(PicFactory.RB_UN_NORMAL), x, y, null);
			}
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.Icon#getIconWidth()
	 */
	public int getIconWidth() {
		return 24;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.Icon#getIconHeight()
	 */
	public int getIconHeight() {
		return 24;
	}
} // end class RadioButtonIcon